/*
package com.shiku.payment.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.shiku.im.comm.constants.KConstants;
import com.shiku.im.comm.ex.ServiceException;
import com.shiku.im.pay.constants.ConsumeRecordEnum;
import com.shiku.im.pay.dao.ConsumeRecordDao;
import com.shiku.im.pay.entity.BaseConsumeRecord;
import com.shiku.im.user.constants.MoneyLogConstants.MoenyAddEnum;
import com.shiku.im.user.constants.MoneyLogConstants.MoneyLogEnum;
import com.shiku.im.user.constants.MoneyLogConstants.MoneyLogTypeEnum;
import com.shiku.im.user.entity.UserMoneyLog;
import com.shiku.im.user.service.UserCoreService;
import com.shiku.payment.api.IPaymentApiService;
import com.shiku.payment.constant.PayConstant;
import com.shiku.payment.dto.*;
import com.shiku.payment.ex.PayOrderException;
import com.shiku.payment.service.PaymentLogicService;
import com.shiku.utils.DateUtil;
import com.shiku.utils.Money;
import com.shiku.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


@Slf4j
public abstract class AbstractPaymentLogicService implements PaymentLogicService {

    protected  final Logger log = LoggerFactory.getLogger(AbstractPaymentLogicService.class);

    @Autowired
    protected IPaymentApiService paymentApiService;


    @Autowired
    protected UserCoreService userCoreService;

    @Autowired
    protected ConsumeRecordDao consumeRecordDao;

  */
/*  @Autowired
    protected PayRedisService payRedisService;


    *//*
*/
/**
     * 订单支付 分布式锁
     *//*
*/
/*
    private static final String PAY_TRANS_LOCK="lock:pay_trans:%s";*//*





    @Override
    public JSONObject submitOrder(int userId,SubmitOrderDTO orderDTO) {
        JSONObject jsonObject =null;
        try {

            if(StringUtil.isEmpty(orderDTO.getSign())){
                throw new  ServiceException(" Sign is null");
            }

            jsonObject=paymentApiService.submitPayOrder(orderDTO);
            */
/**
             * 支付系统返回的支付订单号
             *//*

            //String payOrderId = jsonObject.getString("payOrderId");

            */
/**
             * 商品订单系统的订单号
             *//*


            //String mchOrderNo = jsonObject.getString("mchOrderNo");

            //String payPublicKey = authKeysService.getPayPublicKey(userId);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return jsonObject;
        }

        return jsonObject;
    }

    */
/**
     * 查询支付订单
     * @param payOrderId    支付ID
     * @return
     *//*

    @Override
    public PaymentOrderDTO queryPayOrder(String payOrderId){
        return paymentApiService.queryPayOrder(payOrderId);
    }
    @Override
    public SelectPayChannelResultDTO selectPayChannelRequest(String payOrderId)  {
        SelectPayChannelResultDTO requestResultDTO=null;
        try {
            requestResultDTO=paymentApiService.selectPayChannelRequest(payOrderId);
            return requestResultDTO;
        } catch (PayOrderException e) {
            log.error(e.getMessage(),e);
            throw new ServiceException(e.getErrCode());
        }catch (Exception e) {
            log.error(e.getMessage(),e);
            return requestResultDTO;
        }
    }

    @Override
    public JSONObject doPayRequestBefore(int userId,PayRequestDTO payRequestDTO) throws Exception {
        try {
            //paymentApiService.queryPayOrder(payRequestDTO.getPayOrderId());

            if(PayConstant.PAY_CHANNEL_BALANCE.equals(payRequestDTO.getChannelId())){
               return payOrderByPassWord(userId,payRequestDTO);
            }else{
                return paymentApiService.doPayRequestBefore(payRequestDTO);
            }

            */
/*if(PayConstant.PAY_CHANNEL_ALIPAY.equals(payRequestDTO.getChannelId())){
                return paymentApiService.doPayRequestBefore(payRequestDTO);
            }else if(PayConstant.PAY_CHANNEL_WXPAY.equals(payRequestDTO.getChannelId())){
                return paymentApiService.doPayRequestBefore(payRequestDTO);
            }*//*




        } catch (PayOrderException e) {
            log.error(e.getMessage());
            throw new ServiceException(e.getErrCode());
        }catch (Exception e) {
            log.error(e.getMessage(),e);
            throw  e;
        }
    }


    */
/**
     * @param userId
     * @param payRequestDTO
     * @return
     *//*

    @Override
    public JSONObject doPayRequest(int userId,PayRequestDTO payRequestDTO) throws Exception {
        return null;
    }

    */
/**
     * 余额支付密码支付
     * @param userId
     * @param payRequestDTO
     * @return
     * @throws Exception
     *//*

    @Override
    public JSONObject payOrderByPassWord(int userId, PayRequestDTO payRequestDTO)throws Exception{
        return payOrderByPassWordOnLock(userId,payRequestDTO);
    }

    protected JSONObject payOrderByPassWordOnLock(int userId,PayRequestDTO payRequestDTO)throws Exception {
        JSONObject jsonObject =null;
        try {

            if(PayConstant.PAY_CHANNEL_BALANCE.equals(payRequestDTO.getChannelId())){
                */
/**
                 * 余额支付
                 *//*

                jsonObject=paymentApiService.doPayRequestBefore(payRequestDTO);
                if(null==jsonObject) {
                    return null;
                }
                long amount = jsonObject.getLongValue("amount");
                String mchOrderNo = jsonObject.getString("mchOrderNo");
                double amountDouble = Money.fromCentToDouble(amount);
                userCoreService.payMoenyBalanceOnLock(userId, amountDouble, call -> {

                        UserMoneyLog userMoneyLog =new UserMoneyLog(userId,userId,mchOrderNo,amountDouble,
                                MoenyAddEnum.MOENY_REDUCE, MoneyLogEnum.MALL_SHOP_PAY, MoneyLogTypeEnum.NORMAL_PAY);
                        userMoneyLog.setExtra("商城付款");

                        userCoreService.rechargeUserMoenyV1(userMoneyLog);

                        PaySuccessDTO paySuccessDTO=new PaySuccessDTO();
                        paySuccessDTO.setPayOrderId(payRequestDTO.getPayOrderId());

                        paySuccessDTO.setChannelId(payRequestDTO.getChannelId());
                        paySuccessDTO.setPaySuccessTime(DateUtil.currentTimeSeconds());
                        paySuccessDTO.setAmount(amount);
                        paySuccessDTO.setMchOrderNo(mchOrderNo);
                        //创建消费记录
                        BaseConsumeRecord record=new BaseConsumeRecord();
                        record.setUserId(userId);
                        record.setTradeNo(mchOrderNo);
                        record.setMoney(amountDouble);
                        record.setCurrentBalance(userMoneyLog.getEndMoeny());
                        record.setBusinessId(mchOrderNo);

                        record.setStatus(KConstants.OrderStatus.END);
                        record.setType(ConsumeRecordEnum.MALL_ORDER_PAY.getType());
                        record.setChangeType(KConstants.MOENY_REDUCE);
                        record.setPayType(KConstants.PayType.BALANCEAY); //余额支付
                        record.setDesc("商城付款");
                        record.setTime(DateUtil.currentTimeSeconds());
                        consumeRecordDao.addConsumRecord(record);

                        paymentApiService.paySuccess(paySuccessDTO);
                        return true;
                });

                return jsonObject;
            }



        } catch (PayOrderException e) {
            log.error(e.getMessage());
            throw new ServiceException(e.getErrCode());
        }

        return jsonObject;
    }


}
*/
